function load_image(url,func) {
	var img = new Image(); 
	img.src = url;
	func.call(img);
}

function cloneObject(source) {
    for (i in source) {
        if (typeof source[i] == 'source') {
            this[i] = new cloneObject(source[i]);
        }else{
            this[i] = source[i];
        }
    }
}

(function($){
	$.fn.fadeable = function(options){
		var settings = {
			target: this,
			duration: 'fast'
		};
		$.extend(settings, options);
		$(this).live('hover', function(event) {
			switch(event.type){
				case 'mouseenter':
					$(this).find(settings.target).stop().fadeTo(settings.duration, 0.9);
					break;
				case 'mouseleave':
					$(this).find(settings.target).stop().fadeTo(settings.duration, 0);
					break;
			}
		});
	};
})(jQuery);

function addImageData(data,appendtarget,thumbtpl,titleinput,duration) {
	getTpl(thumbtpl,function(){
		var tpl_ins = $('#'+thumbtpl+'_tpl');
		var lis = $(Mustache.to_html(tpl_ins.html(), data));
		$('#'+appendtarget).removeClass("hide");
		$(lis).addClass('hide');
		var thumbsbefore = $('#'+appendtarget).find('>div');
		$('#'+appendtarget).append(lis);
		$(lis).fadeIn(duration);
		//$('#'+titleinput).val(data.name).focus();
		if(!isEmpty(data.title)&&isInputEmpty($('#'+titleinput))){
			$('#'+titleinput).val(data.title).focus();
		}
		if(!isEmpty(data.price)&&isInputEmpty($('#'+appendtarget).parent().find('.price'))){
			$('#'+appendtarget).parent().find('.price').val(data.price);
		}
		if(!isEmpty(data.url)&&isInputEmpty($('#'+appendtarget).parent().find('.refurl'))){
			$('#'+appendtarget).parent().find('.refurl').val(data.url);
		}
		lis.find('.pzucoverbtn').bind('click', function(event) {
			if($(this).parent().parent().hasClass("cover")){
				$(this).parent().parent().removeClass("cover");
			}else{
				$(this).parent().parent().parent().find(".cover").removeClass("cover");
				$(this).parent().parent().addClass("cover");
				if(!$(this).parent().parent().hasClass("selected")){
					$(this).parent().parent().addClass("selected");
				}
			}
		});
		lis.find('.pzudeletebtn').bind('click', function(event) {
			if($(this).parent().parent().hasClass("selected")){
				$(this).parent().parent().removeClass("selected");
				if($(this).parent().parent().hasClass("cover")){
					$(this).parent().parent().removeClass("cover");
				}
			}else{
				$(this).parent().parent().addClass("selected");
			}
		});
		lis.find('.pzuinsertvideobtn').bind('click', function(event) {
			var editorid = $(this).attr('data-editor');
			var flv = $(this).attr('data-flv');
			($.oFEditor(editorid)).insertFlvTag(flv);
			if(!$(this).parent().parent().hasClass("selected")){
				$(this).parent().parent().addClass("selected");
			}
		});
		lis.find('.pzuinsertuploadimgbtn').bind('click', function(event) {
			var editorid = $(this).attr('data-editor');
			var aid = $(this).attr('data-aid');
			($.oFEditor(editorid)).insertAttachimgTag(aid);
			if(!$(this).parent().parent().hasClass("selected")){
				$(this).parent().parent().addClass("selected");
			}
		});
		lis.find('.pzuinsertuploadfilebtn').bind('click', function(event) {
			var editorid = $(this).attr('data-editor');
			var aid = $(this).attr('data-aid');
			($.oFEditor(editorid)).insertAttachTag(aid);
			if(!$(this).parent().parent().hasClass("selected")){
				$(this).parent().parent().addClass("selected");
			}
		});
		lis.find('.pzuinsertfetchbtn').bind('click', function(event) {
			var editorid = $(this).attr('data-editor');
			var url = $(this).attr('data-url');
			($.oFEditor(editorid)).insertRemoteFetchImgTag(url);
			if(!$(this).parent().parent().hasClass("selected")){
				$(this).parent().parent().addClass("selected");
			}
		});
		var covers = $('#'+appendtarget).find(".cover").length;
		if(data.iscover){
			$(lis).find('.pzucoverbtn').click();
		}else if(covers==0){
			var thumbs = $('#'+appendtarget).find('>div');
			if(thumbs&&thumbs.length==1||thumbsbefore.length==0){
				$(thumbs[0]).find('.pzucoverbtn').click();
			}
		}
		var type = data.type;
		if (type == 'taobao') {
			
		} else if (type == 'web') {
			
		} else if (type == 'video') {
			
		}
		
		
	 });
};
$(function(){
	$.extend({
	    includecss: function(file) {
	       var files = typeof file == "string" ? [file]:file;
	       for (var i = 0; i < files.length; i++) {
	           var tag = "link";
	           var attr = " type='text/css' rel='stylesheet' ";
	           var link = "href" + "='" + file + "'";
	           if ($(tag + "[" + link + "]").length == 0) $('body').append("<" + tag + attr + link + "></" + tag + ">");
	       }
	  },
	  includejs: function(file) {
	       var files = typeof file == "string" ? [file]:file;
	       for (var i = 0; i < files.length; i++) {
	           var tag = "script";
	           var attr = " language='javascript' type='text/javascript' ";
	           var link = "src" + "='" + file + "'";
	           if ($(tag + "[" + link + "]").length == 0) $('body').append("<" + tag + attr + link + "></" + tag + ">");
	       }
	  }
	});
});

(function($){
	$.fn.fetchRemote = function(options){
		var settings = {
			url: '',
			popuptpl: 'address_input',
			thumbtpl:'swfupload_thumb_fetch',
			thumbdiv:'pzuimg-thumbs',
			titleinput:'publish_title',
			editorid:'publish_editor',
			duration: 1000
		};
		$.extend(settings, options);
		$(this).bind('click', function(event) {
			showDialog(settings.popuptpl,function(){
				var lis = getStaticDialog().elem;
				var ainput = lis.find('input');
				ainput.focus();
				getStaticDialog().getbody().find('button').bind('click', function(event) {
					var remote_url = ainput.val();
					if (remote_url == null || remote_url == '') {
						ainput.focus();
						return false;
					}
					getStaticDialog().hide();
					var data= {'remote_url': remote_url};
					ajaxpost(settings.url, data, 
							function(result){
								var data = result.data;
								data['editorid']=settings.editorid;
								if(data.type == 'web'){
									var images = data.images;
									var imgnum = images.length;
									var loadednum = 0;
									for (var i = 0; i < images.length; i++) {
								    	var image = images[i];
								    	imageReady(image.imageurl,image,
												function(r){
													if(this.width>min_fetch_width&&this.height>min_fetch_height){
														var newdata = new cloneObject(data);
														newdata.images = new Array(r);
														addImageData(newdata,settings.thumbdiv,settings.thumbtpl,settings.titleinput,settings.duration);
														imgnum--;
													}else{
														loadednum++;
													}
												},
												function(r){
													loadednum++;
													if(loadednum==images.length&&imgnum==images.length){
														showInfo(sprintf(tip_remote_fetch_nomatch,min_fetch_width,min_fetch_height));
													}
												},
												function(r){
												}
										);
								    }
								}else{
									addImageData(data,settings.thumbdiv,settings.thumbtpl,settings.titleinput,settings.duration);
								}
							},
							function(result){
								showError(result.message);
							});
				});
			});
		});
	};
})(jQuery);

(function($){
	$.fn.openDialog = function(options){
		var settings = {
			acturl: '',
			tpl: '',
			form: '',
			dataurl:''
		};
		$.extend(settings, options);
		if(!isEmpty($(this).attr('data-acturl'))&&isEmpty(settings.acturl)){
			settings.acturl = $(this).attr('data-acturl');
		}
		if(!isEmpty($(this).attr('data-tpl'))&&isEmpty(settings.tpl)){
			settings.tpl = $(this).attr('data-tpl');
		}
		if(!isEmpty($(this).attr('data-dataurl'))&&isEmpty(settings.dataurl)){
			settings.dataurl = $(this).attr('data-dataurl');
		}
		if(!isEmpty($(this).attr('data-form'))&&isEmpty(settings.form)){
			settings.form = $(this).attr('data-form');
		}
		$(this).live('click', function(event) {
			getTpl(settings.tpl,function(){
				var data = {};
				ajaxget(settings.dataurl, data, 
					function(result){
						var tpl_ins = $('#'+settings.tpl+'_tpl');
						var body = $(tpl_ins.html()).find('div.pbody');
						var lis = $(Mustache.to_html(body.html(), result));
						var width = body.attr('data-width');
						var title = body.attr('data-title');
						var css = body.attr('data-css-class');
						var d=getStaticDialog().width(width).head(title).body(lis);
						d.elem.addClass(css);
						d.show();
						$.oValidate(settings.form);
					},
					function(result){
						showError(result.message);
					});
				 
			 });
		});
	};
})(jQuery);

(function($){
	$.fn.openConfirm = function(options){
		var settings = {
			acturl: '',
			tpl: '',
			note: '',
			form: ''
		};
		$.extend(settings, options);
		$(this).live('click', function(event) {
			var tpl=settings.tpl,form=settings.form,acturl=settings.acturl,note=settings.note;
			if(!isEmpty($(this).attr('data-tpl'))){
				tpl = $(this).attr('data-tpl');
			}
			if(!isEmpty($(this).attr('data-form'))){
				form = $(this).attr('data-form');
			}
			if(!isEmpty($(this).attr('data-acturl'))){
				acturl = $(this).attr('data-acturl');
			}
			if(!isEmpty($(this).attr('data-note'))){
				note = $(this).attr('data-note');
			}
			getTpl(tpl,function(){
				var data = {acturl:acturl,note:note};
				var tpl_ins = $('#'+tpl+'_tpl');
				var body = $(tpl_ins.html()).find('div.pbody');
				var lis = $(Mustache.to_html(body.html(), data));
				var width = body.attr('data-width');
				var title = body.attr('data-title');
				var css = body.attr('data-css-class');
				var d=getStaticDialog().width(width).head(title).body(lis);
				d.elem.addClass(css);
				d.show();
				$.oValidate(form);
			 });
		});
	};
})(jQuery);

(function($){
	$.fn.popcategory = function(options,callback){
		var settings = {
			top: '',
			left: '',
			targetid: '',
			width: '370px',
			duration: 'fast',
			showRoot:false,
			tpl: ''
		};
		$.extend(settings, options);
		if(!isEmpty($(this).attr('data-tpl'))&&isEmpty(settings.tpl)){
			settings.tpl = $(this).attr('data-tpl');
		}
		if(!isEmpty($(this).attr('data-top'))&&isEmpty(settings.top)){
			settings.top = $(this).attr('data-top');
		}
		if(!isEmpty($(this).attr('data-left'))&&isEmpty(settings.left)){
			settings.left = $(this).attr('data-left');
		}
		if(!isEmpty($(this).attr('data-targetid'))&&isEmpty(settings.targetid)){
			settings.targetid = $(this).attr('data-targetid');
		}
		var self = $(this);
		
		function hidepop(){
			var popcategory = $('#'+settings.targetid).find('.popcategory');
			$(popcategory).stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
		};
		
		function showpop(){
			var popcategory = $('#'+settings.targetid).find('.popcategory');
			$(popcategory).stop().fadeTo(settings.duration, 1,function(){$(this).css('display','block');});
		};
		
		$(this).live('click', function(event) {
			event.preventDefault();
			var loaded = $('#'+settings.targetid).attr('data-loaded');
			if(loaded=='1'){
				var popcategory = $('#'+settings.targetid).find('.popcategory');
				if(popcategory.css('display')=='block'){
					hidepop();
				}else{
					showpop();
				}
			}else{
				getTpl(settings.tpl,function(){
					var tpl_ins = $('#'+settings.tpl+'_tpl');
					var body = $(tpl_ins.html()).find('div.popcategory');
					$('#'+settings.targetid).append(body);
					$(body).css('position','absolute');
					$(body).css('z-index','8');
					$(body).css('left',settings.left);
					$(body).css('top',settings.top);
					$(body).css('width',settings.width);
					$(body).addClass('popcategory');
					if(settings.showRoot){
						$(body).find('>ul').prepend('<li class="popup-item"><a href="javascript:;" data-id="0">'+tip_select+'</a></li>');
					}
					$('#'+settings.targetid).attr('data-loaded','1');
					showpop();
				 });
			}
		});
		
		$('#'+settings.targetid).find('.popcategory').live('hover', function(event) {
			switch(event.type){
			case 'mouseenter':
				break;
			case 'mouseleave':
				$(this).stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
				break;
			}
		});
		$('#'+settings.targetid).find('.popup-item > a').live('click', function(event) {
			$('#'+settings.targetid).find('span.select_title').text($(this).text());
			$('#'+settings.targetid).find('.select_id').val($(this).attr('data-id'));
			$('#'+settings.targetid).find('input.select_title').val($(this).text());
			callback.call($('#'+settings.targetid), $(this).attr('data-id'));
			hidepop();
		});
		
		$('#'+settings.targetid).find('.popup-item-parent').live('hover', function(event) {
				switch(event.type){
				case 'mouseenter':
					var len = $(this).parents('.popup-item-parent').length;
					var left = $(this).parent().parent().position().left;
					var width = $(this).parent().parent().width();
					if(len>0&&len%2==0){
						$(this).find('>.selectpopup').css('left',(-left)+'px').css('top','20px');
					}else if(left!=0){
						$(this).find('>.selectpopup').css('left',left+'px');
					}
					$(this).find('>.selectpopup').stop().fadeTo(settings.duration, 1,function(){$(this).css('display','block');});
					break;
				case 'mouseleave':
					$(this).find('>.selectpopup').stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
					break;
			}
		});
	};
})(jQuery);


(function($){
	$.fn.popcrop = function(options,callback){
		var settings = {
			top: '',
			left: '',
			targetid: '',
			width: '370px',
			duration: 'fast',
			showRoot:false,
			tpl: ''
		};
		$.extend(settings, options);
		if(!isEmpty($(this).attr('data-tpl'))&&isEmpty(settings.tpl)){
			settings.tpl = $(this).attr('data-tpl');
		}
		if(!isEmpty($(this).attr('data-top'))&&isEmpty(settings.top)){
			settings.top = $(this).attr('data-top');
		}
		if(!isEmpty($(this).attr('data-left'))&&isEmpty(settings.left)){
			settings.left = $(this).attr('data-left');
		}
		if(!isEmpty($(this).attr('data-targetid'))&&isEmpty(settings.targetid)){
			settings.targetid = $(this).attr('data-targetid');
		}
		var self = $(this);
		var crop_sid,crop_cid,crop_type,crop_url,crop_imgpath,crop_imgpath_rel,crop_position,crop_style,crop_width,crop_height,crop_uid;
		
		function hidepop(){
			var popcategory = $('#'+settings.targetid).find('.popcategory');
			$(popcategory).stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
		};
		
		function showpop(){
			var popcategory = $('#'+settings.targetid).find('.popcategory');
			$(popcategory).stop().fadeTo(settings.duration, 1,function(){$(this).css('display','block');});
		};
		
		$(this).live('click', function(event) {
			event.preventDefault();
			var loaded = $('#'+settings.targetid).attr('data-loaded');
			if(loaded=='1'){
				var popcategory = $('#'+settings.targetid).find('.popcategory');
				if(popcategory.css('display')=='block'){
					hidepop();
				}else{
					showpop();
				}
			}else{
				getTpl(settings.tpl,function(){
					var tpl_ins = $('#'+settings.tpl+'_tpl');
					var body = $(tpl_ins.html()).find('div.popcategory');
					$('#'+settings.targetid).append(body);
					$(body).css('position','absolute');
					$(body).css('z-index','8');
					$(body).css('left',settings.left);
					$(body).css('top',settings.top);
					$(body).css('width',settings.width);
					$(body).addClass('popcategory');
					if(settings.showRoot){
						$(body).find('>ul').prepend('<li class="popup-item"><a href="javascript:;" data-id="0">'+tip_select+'</a></li>');
					}
					$('#'+settings.targetid).attr('data-loaded','1');
					showpop();
				 });
			}
		});
		
		$('#'+settings.targetid).find('.popcategory').live('hover', function(event) {
			switch(event.type){
			case 'mouseenter':
				break;
			case 'mouseleave':
				$(this).stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
				break;
			}
		});
		$('#'+settings.targetid).find('.popup-item > a').live('click', function(event) {
			alert('test');
			$(self).find('span.select_title').text($(this).text());
			$('#'+settings.targetid).find('.select_id').val($(this).attr('data-id'));
			$('#'+settings.targetid).find('input.select_title').val($(this).text());
			callback.call(self, $(this).attr('data-id'));
			hidepop();
		});
		
		$('#'+settings.targetid).find('.popup-item-parent').live('hover', function(event) {
				switch(event.type){
				case 'mouseenter':
					var len = $(this).parents('.popup-item-parent').length;
					var left = $(this).parent().parent().position().left;
					var width = $(this).parent().parent().width();
					if(len>0&&len%2==0){
						$(this).find('>.selectpopup').css('left',(-left)+'px').css('top','20px');
					}else if(left!=0){
						$(this).find('>.selectpopup').css('left',left+'px');
					}
					$(this).find('>.selectpopup').stop().fadeTo(settings.duration, 1,function(){$(this).css('display','block');});
					break;
				case 'mouseleave':
					$(this).find('>.selectpopup').stop().fadeTo(settings.duration, 0,function(){$(this).css('display','none');});
					break;
			}
		});
	};
})(jQuery);

(function($){
	$.fn.clickSelectedTo = function(options){
		var settings = {
			selectedclass:'selected',
			insertpath:'>a',
			maxselected:5,
			targetarea:'publish_editor'
		};
		var self = this;
		$.extend(settings, options);
		var dtxt = $('#'+settings.targetarea).attr('data-default');
		$('#'+settings.targetarea).val(dtxt);
		$(this).find('li').bind('click', function(event) {
			$selected = $(this).parent().find('.'+settings.selectedclass);
			if($selected&&$selected.length>=settings.maxselected&&!$(this).hasClass(settings.selectedclass)){
				alert(sprintf(tip_publish_tagmax,settings.maxselected));
				return;
			}
			var textinsert = $(this).find(settings.insertpath).text()+' ';
			if($(this).hasClass(settings.selectedclass)){
				$(this).removeClass(settings.selectedclass);
				var text = $('#'+settings.targetarea).val();
				text = str_replace(textinsert, '',text);
				text = str_replace(trim(textinsert), '',text);
				$('#'+settings.targetarea).val(text?text:'');
			}else{
				$(this).addClass(settings.selectedclass);
				$('#'+settings.targetarea).insertAtCaret(textinsert,0);
			}
		});
		$('#'+settings.targetarea).bind('keyup', function(event) {
			var text = $(this).val();
			if(text!=undefined&&text!=null){
				var tags = text.split(' ');
				if(tags.length>=settings.maxselected){
					var t = [];
					for (i = 0; i < settings.maxselected; i++) {
						t[i] = tags[i];
					}
					tags = t;
					$(this).val(t.join(' '));
				}
				self.find('li').each(function(){
					var textinsert = $(this).find(settings.insertpath).text();
					for (i = 0, fl = tags.length; i < fl; i++) {
						var temp = tags[i] + '';
						$(this).removeClass(settings.selectedclass);
						if(trim(textinsert)==trim(temp)){
							$(this).addClass(settings.selectedclass);
							return;
						}
					}
					
				});
				
			}
		});
		
	};
})(jQuery);


(function($){
	$.fn.pageScroll = function(options){
		var settings = {
				dur : 1000,
				doc : "bd",
				elementOffsettop : 125,
				elementOffsetLeft : 20,
				elementOffsetRight : 0,
				elementOffsetBottom : 0
		};
		var self = this;
		$.extend(settings, options);
		$(self).removeClass('hide');
		$(window).resize(function(){
				var full_width = $(this).width();
				var body_width = $('#'+settings.doc).width();
				var body_left = (full_width-body_width)/2;
				var body_right = (full_width-body_width)/2;
				$(self).css('position','fixed');
				if(settings.elementOffsetRight!=0){
					$(self).css('bottom',settings.elementOffsetBottom);
				}
				if(settings.elementOffsettop!=0){
					$(self).css('top',settings.elementOffsettop);
				}
				var left = 0;
				var right = 0;
				if(settings.elementOffsetLeft!=0){
					left = settings.elementOffsetLeft+body_left;
				}
				if(settings.elementOffsetRight!=0){
					right = settings.elementOffsetRight+body_right;
				}
				
				if(left!=0){
					if(left>0){
						$(self).css('left',left);
					}else{
						$(self).css('left',20);
					}
				}
				
				if(right!=0){
					var swidth = $(self).width();
					if(right+swidth>full_width){
						$(self).css('right',20);
					}else{
						$(self).css('left',right);
					}
				}
		  });
		
		$(window).resize();
		
	};
})(jQuery);


(function($) {
	$.fn.gallary = function(options){
		var settings = {
			target: this,
			viewpoint: null,
			thumbs:null
		};
		$.extend(settings, options);
		var lis = settings.thumbs.find("li");
		var k = lis.size();
		var f = new Array(k),fancy = new Array(k),i = 1,cover_index=0;
		lis.each(function(r) {
			var q = $(this).attr("url");
			var t = $(this).attr("title");
			loadimg(q,t,r);
			if($(this).hasClass("on")){
				cover_index = r;
			}
			$(this).bind("click",
			function() {
				i = r + 1;
				next_shot();
			}).bind("mouseover",
			function() {
				$(this).css({
					opacity: 0.8
				});
			}).bind("mouseout",
			function() {
				$(this).css({
					opacity: 1
				});
			});
		});

		settings.viewpoint.find("img").bind("click",
				function() {
					$.fancybox(fancy, {
								'index'             : cover_index,
								'transitionIn'		: 'none',
								'transitionOut'		: 'none',
								'titlePosition' 	: 'over',
								'type'              : 'image'
							});
		});
		function loadimg(q,t,r) {
			load_image(q,
			function(s) {
				f[r] = this;
				fancy[r] = {'href'	: q,
							'title'	: t};
			});
		}
		function next_shot() {
			var s = lis.eq(i - 1);
			if (f[i - 1] && f[i - 1].src) {
				settings.viewpoint.empty();
				//settings.viewpoint.append(f[i - 1]);
				var r = f[i - 1].src;
				var t = '<img src="' + r + '"/>';
				settings.viewpoint.html(t);
			} else {
				var r = s.attr("url");
				var t = '<img src="' + r + '" width="' + s.attr("width") + '" height="' + s.attr("height") + '"/>';
				settings.viewpoint.html(t);
			}
			settings.thumbs.find("li.on").removeClass("on");
			settings.viewpoint.find("img").bind("click",
			function() {
				$.fancybox(fancy, {
							'index'             : i - 1,
							'transitionIn'		: 'none',
							'transitionOut'		: 'none',
							'type'              : 'image',
							'titlePosition' 	: 'over'
						});
			});
			lis.eq(i - 1).addClass("on");
		}
	};
	
})(jQuery);


(function(a) {
	a.fn.slideShow = function(d) {
		var b = a.extend({}, a.fn.slideShow.defaults, d), n = typeof (b.slides) === "object" ? b.slides
				: a(b.slides), o = typeof (b.trigs) === "object" ? b.trigs
				: a(b.trigs), e = o.find(b.follow), s = n.children(), r = o
				.children(b.tritag), p = r.length, k = r.eq(0).outerHeight(), c = 0, j = 0, i = 0, h = a.browser.msie, f;
		var q = function(u) {
			var w = n.find(".slide-" + j), t = n.find(".slide-" + c), v = t
					.css("zIndex");
			pre_zi = w.css("zIndex");
			if (j !== c) {
				t.css({
					zIndex : 4
				});
				w.css({
					zIndex : 5
				});
				w.fadeOut("fast", function() {
					a(this).css({
						display : "block",
						zIndex : 1
					})
				})
			}
			if (h) {
				e.css({
					top : k * c
				})
			} else {
				e.stop(true).animate({
					top : k * c
				}, "fast", function() {
					e.css({
						top : k * c
					})
				})
			}
			j = c;
			if (u) {
				m()
			}
		}, l = function() {
			var t = s.length;
			s.each(function(w, u) {
				var x = a(this), y;
				x.css({
					zIndex : 1,
					display : "block"
				});
				if (w === 0) {
					x.css({
						zIndex : 5
					})
				}
				x.addClass("slide-" + w)
			});
			r.each(function(w, u) {
				var x = a(this), y;
				x.addClass("trig-" + w)
			})
		}, m = function() {
			i = setTimeout(function() {
				c = c + 1 >= p ? 0 : c + 1;
				q(1)
			}, b.timer)
		}, g = function() {
			clearTimeout(i)
		}, f;
		l();
		m();
		(function() {
			var t;
			o.delegate(b.tritag, "mouseover mouseout", function(v) {
				v.preventDefault();
				v.stopPropagation();
				var u = a(this);
				if (v.type === "mouseover") {
					g();
					clearTimeout(t);
					t = setTimeout(function() {
						c = parseInt(u.attr("class").match(/\d/g)[0]);
						q(0)
					}, 100)
				} else {
					if (v.type === "mouseout") {
						m()
					}
				}
			})
		})();
		n.bind("mouseover mouseout", function(t) {
			if (t.type === "mouseover") {
				g()
			} else {
				if (t.type === "mouseout") {
					m()
				}
			}
		})
	};
	a.fn.slideShow.defaults = {
		slides : "",
		trigs : "",
		tritag : "",
		follow : "",
		timer : 4000
	}
})(jQuery);

$(document).ready(function() {
	$("#indexSlide").slideShow({
		slides : $("#indexLeft"),
		trigs : $("#indexRight"),
		follow : "div",
		tritag : "a"
	});
	$('.puzzing').fadeable({target: '.puzzing-txt'});
	$('[rel=tooltip]').tooltip({animation: true});
	$('[rel=contact]').tooltip({placement:'bottom',animation: true});
	$('img.avatar').error(function() {
		 $(this).attr("src", base_url+'assets/img/avatar_large.jpg');
	});
	$('img.avatar-mid').error(function() {
		 $(this).attr("src", base_url+'assets/img/avatar_middle.jpg');
	});
	$('img.avatar-small').error(function() {
		 $(this).attr("src", base_url+'assets/img/avatar_large.jpg');
	});
	$('.puzz-thumb a.puzzing-txt').each(function() {
		var link = $(this);
		link.tooltip({
			placement:'bottom',
			gravity: 'n',
			html: true,
			title: function() { return link.closest('li').find('div.tooltip-player').html(); }
		});
	});
	$('a.dropdown-toggle').bind('click',function(){
		if(!isEmpty($(this).attr('href'))){
			window.location.href = $(this).attr('href');
		}
	});
	$(function(){
		$('form').each(function() {
			if($(this).attr('id')){
				$.oValidate($(this).attr('id'));
			}
		});
	});
	$('[data-rel=dialog]').openDialog({form: 'dialogform'});
	$('[data-rel=confirm]').openConfirm({tpl: 'confirm',form: 'confirmform'});
	$(function(){
	    $('[placeholder]').focus(function() {
	      var input = $(this);
	      if (input.val() == input.attr('placeholder')) {
	        input.val('');
	        input.removeClass('placeholder');
	      }
	    }).blur(function() {
	      var input = $(this);
	      if (input.val() == '' || input.val() == input.attr('placeholder')) {
	        input.addClass('placeholder');
	        input.val(input.attr('placeholder'));
	      }
	    });

	    $('[placeholder]').parents('form').submit(function() {
	      $(this).find('[placeholder]').each(function() {
	        var input = $(this);
	        if (input.val() == input.attr('placeholder')) {
	            input.val('');
	        }
	      });
	    });
	});
	$('[placeholder]').each(function(){
		if ($(this).val() == ''){
			$(this).val($(this).attr('placeholder'));
		}
		});
});